package com.fuze.questionnaire.controller;

import com.fuze.questionnaire.common.Result;
import com.fuze.questionnaire.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * @author sepc_
 * @date 11/9/2021 14:32
 * 问卷问题API
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@Api(tags = "问卷问题API")
public class QuestionController {

    final QuestionService questionService;

    /**
     * 查询全部的问卷问题类型
     * @return 问卷问题类型列表
     */
    @ApiOperation("问卷问题类型查询")
    @GetMapping("/query/type")
    public Result listProjectType() {
        return Result.ok(questionService.listProjectType());
    }

    /**
     * @param typeId 类型id
     * @return 单一类型下的全部问题（已经排序）
     */
    @ApiOperation(value = "问卷问题查询")
    @GetMapping("/query/{typeId:\\d+}")
    public Result query(@PathVariable(name = "typeId") @NotNull Integer typeId) {
        return Result.ok(questionService.query(typeId));
    }

}
